package vip.ola.code.secruity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import vip.ola.code.common.service.RpcCommonService;
import vip.ola.core.entity.code.CodeUser;

@Service
public class JwtUserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private RpcCommonService rpcService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        CodeUser codeUser = rpcService.codeUserService.getByName(username);
        if (codeUser == null) {
            return null;
        } else {
            return JwtUserFactory.create(username, codeUser);
        }
    }
}
